import { create } from "zustand";
import { bannerGet } from "../api/course";
import { BannerType } from "../type/course";
interface BannerStateType {
  banner: Array<BannerType>;
  fetchBanner: () => void;
  addBanner: (obj: BannerType) => void;
}
export const useBanner = create<BannerStateType>((set, get) => ({
  banner: [],
  async fetchBanner() {
    let res = await bannerGet();
    set(() => ({
      banner: res.data.results,
    }));
  },
  addBanner(obj) {
    let banner = get().banner; //get获取到的是当前状态机模块对象
    banner.push(obj);
    set({ banner });
  },
}));
